"""
新建用户
"""
import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool

# 测试用例数据
case_data = {'module':'用户管理','caseid':'导入','account':'zhangsan','username':'张三'}

@pytest.mark.基础管理系统
@pytest.mark.组织管理
@allure.step(case_data['caseid'])
def test_case(playwright : Playwright) -> None:
    # 测试结果标题
    allure.dynamic.feature(case_data['module'])
    allure.dynamic.title(case_data['caseid'])
    allure.dynamic.suite(case_data['caseid'])

    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    page.wait_for_timeout(2000)

    page.goto(url + url_yonghuguanli)
    page.wait_for_timeout(2000)
    page.get_by_text("账号姓名查询清空").click()

    page.get_by_role("button", name=" 导入").click()
    with page.expect_file_chooser() as fc_info:
        page.get_by_label("导入").locator("i").nth(2).click()
    file_chooser = fc_info.value
    file_chooser.set_files(test_datas_dir+"\用户导入模板.xlsx")

    # 断言
    expect(page.get_by_text('新建成功！')).to_be_visible()

    # 测试结果截图
    filename = os.path.join(test_screenshot_dir, f"{case_data['caseid']}.png")
    page.screenshot(path=filename)
    allure.attach.file(source=filename, name=case_data['caseid'],
                       attachment_type=allure.attachment_type.PNG)


    # page.get_by_text("账号姓名查询清空").click()
    # page.get_by_placeholder("请输入账号").fill(case_data['account'])
    # page.get_by_role("button", name=" 查询").click()
    # # 获取tbody下面元素tr个数
    # expect(page.locator("tbody > tr")).to_have_count(1)
    # # 获取是否存在文本text
    # expect(page.locator("tbody")).to_contain_text(case_data['account'])
    # page.get_by_role("button", name="删除").click()
    # page.get_by_role("button", name="确 定").click()
    # expect(page.get_by_text('删除成功！')).to_be_visible()

    SetupTeardown.close()
